//???????will strings be frees too soon?
#include<iostream>
#include<vector>
#include<string>
using namespace std;

vector<string> get_longest_strings(const vector<string> &s) {
   int max=0;
   for(int i=0; i<s.size(); i++) {
      int a=s[i].length();
      if(a>max) max=a;
   }

   vector<string> res;
   for(int i=0; i<s.size(); i++) {
      if(s[i].length()==max) {
         string t=s[i];
         res.push_back(t); //use the copies as results
      }
   }
   return res;
}
int main() {
   vector<string> listA;
   listA.push_back("hi");
   listA.push_back("hello");
   listA.push_back("qwerty");
   //cout<<get_longest_strings(listA); //there is no toString() in C++
   vector<string> res=get_longest_strings(listA);
   for(int i=0; i<res.size(); i++) {
      cout<<res[i]<<endl;
   }
   return 0;
}
